package com.tul.vapp.servicecenter.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tul.cusa.common.util.DateUtil;
import com.tul.cusa.common.util.StringUtil;
import com.tul.vapp.servicecenter.dao.ILogReleaseNamespaceDao;
import com.tul.vapp.servicecenter.entity.LogReleaseNamespace;
import com.tul.vapp.servicecenter.service.ILogReleaseService;
import com.tul.vapp.servicecenter.util.UniqueKeyGenerator;

/**
 * 记录发布日志
 * 
 * @author wwxiang
 * @since 2018/1/13.
 */
@Service
public class LogReleaseService implements ILogReleaseService {

	@Autowired
	private ILogReleaseNamespaceDao namespaceDao;

	@Override
	public void log(String appId, String namespace, String configurations, String operator) {
		String releaseKey = UniqueKeyGenerator.generate(appId, namespace);
		String[] strAry = StringUtil.split(releaseKey, "-");
		String createTime = DateUtil.format(new Date(), DateUtil.DATE_TIME_FORMAT);
		LogReleaseNamespace ns = new LogReleaseNamespace();
		ns.setReleaseKey(releaseKey);
		ns.setReleaseName(strAry[0] + "-release");
		ns.setAppId(appId);
		ns.setNamespace(namespace);
		ns.setConfigurations(configurations);
		ns.setCreateBy(operator);
		ns.setCreateTime(createTime);
		namespaceDao.addLog(ns);
	}

}
